<?php

namespace App\Model\Admin;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Model\Admin\ModelFieldModel
 *
 * @property int $id
 * @property int $model_id 关联模型ID
 * @property string $name 字段名
 * @property string $type 字段类型
 * @property string|null $default_value 字段默认值
 * @property string|null $comment 字段注释
 * @property string $form_name 表单名称
 * @property string $form_type 表单类型
 * @property string|null $form_comment 表单备注
 * @property string|null $form_params 表单参数
 * @property string|null $form_default 表单默认值
 * @property int $is_show 是否显示
 * @property int $is_required 是否推荐
 * @property int $order 排序
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read \App\Model\Admin\SystemModel $model
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Admin\ModelFieldModel newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Admin\ModelFieldModel newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Admin\ModelFieldModel query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Admin\ModelFieldModel whereComment($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Admin\ModelFieldModel whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Admin\ModelFieldModel whereDefaultValue($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Admin\ModelFieldModel whereFormComment($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Admin\ModelFieldModel whereFormDefault($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Admin\ModelFieldModel whereFormName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Admin\ModelFieldModel whereFormParams($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Admin\ModelFieldModel whereFormType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Admin\ModelFieldModel whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Admin\ModelFieldModel whereIsShow($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Admin\ModelFieldModel whereModelId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Admin\ModelFieldModel whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Admin\ModelFieldModel whereOrder($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Admin\ModelFieldModel whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Admin\ModelFieldModel whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class ModelFieldModel extends Model
{
    //
    protected $table = 'model_field';

    const SHOW_DISABLE = 0;
    const IS_REQUIRED = 0;

    public function add($data)
    {
        $this->model_id = $data['model_id'];
        $this->name = $data['name'];
        $this->type = $data['type'];
        $this->default_value = $data['default_value'];
        $this->comment = $data['comment'];
        $this->form_name = $data['form_name'];
        $this->form_type = $data['form_type'];
        $this->form_comment = $data['form_comment'];
        $this->form_params = $data['form_params'];
        $this->form_default = $data['form_default_value'];
        $this->is_show = $data['is_show'];
        $this->order = $data['order'];
        if ($this->save()){
            return true;
        }else{
            return false;
        }
    }

    public function model()
    {
        return $this->belongsTo('App\Model\Admin\SystemModel','model_id');
    }
}
